﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
namespace QuizNet
{
    class clsMonHoc:clsDataLayer
    {
        public clsMonHoc()
        { }
        public bool themMonHoc(MON_HOC _mh)
        {
            try
            {
                Guid g = System.Guid.NewGuid();
                _mh.ma_mon_hoc = g;

                qdb.AddToMON_HOC(_mh);
                
                updateDataBase();
                
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
            
        }
        
        public bool xoaMonHoc(string _mmh)
        {
            try
            {
                Guid g = new Guid(_mmh);
                IQueryable<MON_HOC> xoa = qdb.MON_HOC.Where(x => x.ma_mon_hoc.Equals(g));
                qdb.MON_HOC.DeleteObject(xoa.First());
                updateDataBase();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
                
            }
        }

        public bool suaMonHoc(string _mamh,string _tenmh)
        {
            try
            {
                Guid g = new Guid(_mamh);
                IQueryable<MON_HOC> mhSua = from r in qdb.MON_HOC where r.ma_mon_hoc.Equals(g) select r;
                mhSua.First().ten_mon_hoc = _tenmh;
                updateDataBase();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
                
            }
        }

        public List<MON_HOC> layDSMonHoc()
        {
            List<MON_HOC> lsmh = new List<MON_HOC>();
            lsmh = qdb.MON_HOC.ToList<MON_HOC>();
            return lsmh;
            
        }
    }
}
